package com.dal.constant;

import java.util.Map;

import org.error.LoginErrorCode;

import com.dal.db.bean.ChannelApp;
import com.dal.module.account.platform_verify.HeiTaoVerifyer;
import com.dal.module.account.platform_verify.PlatformVerifyer;
import com.dal.module.account.platform_verify.LocalPlatformVerifyer;
import com.sojoys.artifact.tools.ToolError;

/**
 * 平台账号校验器枚举
 * Created by fxf on 2017/6/26.
 */
public enum PlatformVerifyerEnum {

    TEST(ChannelType.LOCAL_TEST, new LocalPlatformVerifyer()),
    HEI_TAO(ChannelType.HEI_TAO, new HeiTaoVerifyer()),
    ;

    String channelTag;
    PlatformVerifyer verifyer;

    PlatformVerifyerEnum(String channelTag, PlatformVerifyer verifyer) {
        this.channelTag = channelTag;
        this.verifyer = verifyer;
    }

    public static void verify(ChannelApp channelApp,Map param){
        getPlatformVerifyer(channelApp.getChannelPkChannelId().getTag()).verify(channelApp,param);
    }


    public static PlatformVerifyer getPlatformVerifyer(String channelTag){
        for (PlatformVerifyerEnum platformVerifyerEnum : values()) {
            if (platformVerifyerEnum.channelTag.equals(channelTag)) {
                return platformVerifyerEnum.verifyer;
            }
        }
        ToolError.isAndTrue(LoginErrorCode.PLATFORM_ACCOUNT_CHECKER_TYPE_ERR,true);
        return null;
    }
}
